﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Midapex.SmartOrm.Tools.Wizard
{
    public partial class AccessConnForm : Form
    {
        public AccessConnForm()
        {
            InitializeComponent();
        }

        internal string GetConnString()
        {
            if (string.IsNullOrEmpty(this.mdbFile))
                throw new Exception("Invalid access data file path");
 
            return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", mdbFile);
        }

        private void buttonSelectFile_Click(object sender, EventArgs e)
        {
            if(openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                mdbFile = openFileDialog1.FileName;
                this.textBox1.Text = mdbFile;
            }
        }

        string mdbFile;

        private void AccessConnForm_Load(object sender, EventArgs e)
        {
            int tmp = Application.ExecutablePath.LastIndexOf("\\");
            string dir = Application.ExecutablePath.Substring(0, tmp);

            openFileDialog1.InitialDirectory = dir;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.mdbFile))
            {
                MessageBox.Show("Please select a access db file");
                return;
            }

            DialogResult = DialogResult.OK;
        }
    }
}